package com.mystudy.leetcode.problem.tree.p_104;

import com.mystudy.leetcode.base.TreeNode;

/**
 * @program: infoalgorithm
 * @description: 二叉树的最大深度
 * @author: zhouzhilong
 * @create: 2019-07-23 15:11
 **/
public class Solution {
    /**
     * 思路１:求每个子树的深度，谁长加谁
     * @param root
     * @return
     */
    public int maxDepth(TreeNode root) {
        if(root == null){
            return 0 ;
        }

        int leftDepth = maxDepth(root.left);
        int rightDepth = maxDepth(root.right);
        return leftDepth>=rightDepth?leftDepth+1:rightDepth+1;
    }
}
